package com.hbue.water.service.impl;

import com.hbue.water.entity.Customer;
import com.hbue.water.entity.History;
import com.hbue.water.entity.HistoryContainer;
import com.hbue.water.entity.Worker;
import com.hbue.water.mapper.CustomerMapper;
import com.hbue.water.mapper.HistoryMapper;
import com.hbue.water.mapper.WorkerMapper;
import com.hbue.water.service.HistoryContainerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yushu
 * @date 2021/12/31
 * @apiNate
 */
@Service
public class HistoryContainerServiceImpl implements HistoryContainerService {

    @Autowired
    private HistoryMapper historyMapper;

    @Autowired
    private WorkerMapper workerMapper;

    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public HistoryContainer getWorkerListAndCustomerList() {
        List<Worker> workerList = workerMapper.selectList(null);
        List<Customer> customerList = customerMapper.selectList(null);
        HistoryContainer historyContainer = new HistoryContainer();
        historyContainer.setWorkerList(workerList);
        historyContainer.setCustomerList(customerList);
        return historyContainer;
    }

    @Override
    public HistoryContainer getAllInfoById(Integer hid) {
        History history = historyMapper.getHistoryById(hid);
        HistoryContainer historyContainer = this.getWorkerListAndCustomerList();
        historyContainer.setHistory(history);
        return historyContainer;
    }
}
